package com.source.sys.mapper;

import com.source.sys.entity.Popedom;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.sys.vo.PopedomShowVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ZZF
 * @since 2021-02-08
 */
public interface PopedomMapper extends BaseMapper<Popedom> {
    /**
     * 获取权限子菜单
     * @param popedomId
     * @return
     */
    @Select("select son.* from sys_popedom parent, sys_popedom son where parent.pid = #{pid} and son.parentId = parent.pid")
    List<Popedom> getSonPopedom(@Param("pid") String popedomId);

    /**
     * 获取第一级菜单
     * @param parentId
     * @return
     */
    @Select("select * from sys_popedom where parentId = #{parentId}")
    List<Popedom> getFirstLevelPopedom(@Param("parentId") String parentId);

    /**
     * 获取上级菜单
     * @param popdomId
     * @return
     */
    @Select("select parent.* from sys_popedom parent, sys_popedom son" +
            " where son.pid = #{popedomId} and son.parentId = parent.pid")
    Popedom getPrePopedom(@Param("popedomId") String popdomId);

    /**
     * 通过权限第二级菜单名称获取权限对象
     * @param pname 权限名称
     * @param
     * @return
     */
    @Select("SELECT * FROM `sys_popedom` where parentId<>#{parentId} and pname = #{pname}")
    Popedom getSecondPopedomByName(@Param("parentId") String parentId,@Param("pname") String pname);

    @Select("SELECT sys_popedom.* FROM sys_role_popedom,sys_popedom " +
            "WHERE sys_popedom.isShow = 1 AND sys_role_popedom.popedomId = sys_popedom.pid " +
            "AND sys_role_popedom.roleId = #{roleId}")
    List<PopedomShowVo> getThirdPopedomByRoleId(@Param("roleId") String roleId);

    @Select("SELECT sys_popedom.* FROM sys_popedom, sys_role_popedom " +
            "WHERE sys_popedom.isShow = 1 AND sys_role_popedom.popedomId = sys_popedom.pid " +
            "AND sys_role_popedom.roleId = #{roleId} AND permission = #{method} and href LIKE concat('%',#{uri},'%')")
    PopedomShowVo checkUriAndMethodByRoleId(@Param("roleId") String roleId, @Param("uri") String uri,@Param("method") String method);
}
